Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
public_html
/
admin
/
app
/
V2
/
Services
/
Filename :
DocuLockerStorageService.php
back
Copy
<?php namespace App\V2\Services; use App\Models\DocuLocker\UploadedDocument; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; class DocuLockerStorageService { protected $default_storage_name; protected $local_storage; protected $s3_storage; public function __construct() { $this->default_storage_name = config('filesystems.default'); $this->local_storage = Storage::disk('local'); // $this->s3_storage = Storage::disk('s3'); } public function upload($locker, $file, $request) { $document = null; if($this->getDefaultStorageType() == 'local'){ $document = $this->uploadToLocal($locker, $file, $request); } else if($this->getDefaultStorageType() == 'local'){ $document = $this->uploadToS3($locker, $file, $request); } $file_size_bytes = $file->getSize(); $file_size_mb = $file_size_bytes / 1024 / 1024; //from bytes to mb $locker->total_storage_mb = $locker->total_storage_mb + $file_size_mb; $locker->save(); return $document; } private function uploadToLocal($locker, $file, $request) { $path = $file->store('documents'); // Create new document record $document = new UploadedDocument(); $document->document_uuid = (string) Str::uuid(); $document->locker_id = $locker->locker_id; // This is an example. Adjust according to your logic. $document->user_id = $request->user()->user_id; $document->storage_type = $this->getDefaultStorageType(); $document->s3_file_handle = $path; $document->local_file_url = $path; $document->file_name = $file->getClientOriginalName(); $document->file_extension = $file->getClientOriginalExtension(); $document->file_type = $file->getMimeType(); $document->file_source = 'UPLOADED'; $document->save(); return $document; } private function uploadToS3($locker, $file, $request){ } public function download($document) { if(strtolower($document->storage_type) =='local') return Storage::download($document->local_file_url, $document->file_name); else if(strtolower($document->storage_type) == 's3') return Storage::download($document->local_file_url, $document->file_name); else return null; } public function delete($path) { // return $this->storage->delete($path); } public function getDefaultStorageType(){ return $this->default_storage_name; } } ?>